﻿using AutojsController.Config;
using Serilog;
using Serilog.Events;
using System.Collections.Generic;
using System.IO;

namespace AutojsController.Helpers
{
    public static class LoggerFactory
    {
        private static Dictionary<string, ILogger> _loggers = new Dictionary<string, ILogger>();
        public static ILogger GetLogger(string module = "default", LogEventLevel level = LogEventLevel.Information)
        {
            module = module ?? "default";
            if (_loggers.ContainsKey(module)) return _loggers[module];
            string logfile = Path.Combine(Consts.LOG_DIR, $"{module}.log");
            var logger = new LoggerConfiguration().MinimumLevel.Is(level).WriteTo.File(logfile,
                rollingInterval: RollingInterval.Day, outputTemplate: Consts.LOG_FORMAT).CreateLogger();
            _loggers[module] = logger;
            return logger;
        }
    }
}
